/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: IFlyweightFactory.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/8 下午7:10
 * LastModified: 2020/03/08 19:10:08
 */

package com.qolome.knowledge.design.pattern.flyweight.general;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Qolome
 * @version V1.0
 * @Description 享元工厂
 * @date 2020年 03月08日 19:10:14
 */
public class FlyweightFactory {

    private static Map<String,IFlyweight> pool= new HashMap<>();


    /**
     * //因为内部状态具备不变形,因此作为缓存的键
     * @param intrinsicState
     * @return
     */
    public static  IFlyweight geFlyweight(String intrinsicState){
        if(!pool.containsKey(intrinsicState)){
            IFlyweight flyweight = new ConcreteFlyweight(intrinsicState);
            return pool.put(intrinsicState,flyweight);

        }
        return pool.get(intrinsicState);
    }
}
